import {globalShortcut} from "electron";

const hotkeysHook = function (mainWindow) {
	mainWindow.on("focus", () => {
		// mac下快捷键失效的问题
		if (process.platform === "darwin") {
			let contents = mainWindow.webContents;
			globalShortcut.register("CmdOrCtrl+C", () => {
				console.log("注册复制快捷键成功");
				contents.copy();
			});
			globalShortcut.register("CommandOrControl+V", () => {
				console.log("注册粘贴快捷键成功");
				contents.paste();
			});
			globalShortcut.register("CommandOrControl+X", () => {
				console.log("注册剪切快捷键成功");
				contents.cut();
			});
			globalShortcut.register("CommandOrControl+A", () => {
				console.log("注册全选快捷键成功");
				contents.selectAll();
			});
		}
	});
	mainWindow.on("blur", () => {
		globalShortcut.unregisterAll(); // 注销键盘事件
	});
};
export default hotkeysHook;
